package com.complex.javasecurity;

/** */
/**
 * 
 * @author by http://www.bt285.cn http://www.5a520.cn
 * @version 1.0
 * @since 1.0
 */
public class DESCoderTest {

	public static void main(String[] args) {
		try {
			test();
		} catch (Exception e) {

		}

	}

	public static void test() throws Exception {
		String inputStr = "DES";
		// 生成密钥
		String key = DESCoder.initKey();
		System.err.println("原文:\t" + inputStr);

		System.err.println("密钥:\t" + key);

		byte[] inputData = inputStr.getBytes();
		// 加密
		inputData = DESCoder.encrypt(inputData, key);

		System.err.println("加密后:\t" + DESCoder.encryptBASE64(inputData));

		// 解密
		byte[] outputData = DESCoder.decrypt(inputData, key);
		String outputStr = new String(outputData);

		System.err.println("解密后:\t" + outputStr);
		// 判断
		assertEquals(inputStr, outputStr);
	}

	private static void assertEquals(String inputStr, String outputStr) {
		if (inputStr.equals(outputStr)) {
			System.err.println("匹配");
		} else {
			System.err.println("不匹配");
		}
	}
}
